/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * <p>Project: jse2302 - MyCallableDemo
 * <p>Powered by webrx On 2023-06-30 09:08:59
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class MyCallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //Callable<Integer> call 方法 可以实现线程返回结果
        MyCallable<Integer> call = new MyCallable<>();
        call.setNum(100);

        FutureTask<Integer> future = new FutureTask<>(call);

        //建立线程实例
        Thread thread = new Thread(future);

        //线程就绪
        thread.start();

        //get()等待thread结果
        System.out.println(future.get());

        System.out.println("ok");
    }
}
